package com.work.blog.config;

import com.work.blog.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.resource.NoResourceFoundException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:DELL
 * Date:2025-06-16
 * Time:16:28
 */
@ControllerAdvice
@ResponseBody
@Slf4j
//统一异常处理
public class ExceptionHandle {
    @ExceptionHandler//捕获异常
    public Result handle(Exception e){
        log.error("发生异常，e:",e);
        return Result.fail("内部错误，请联系管理员");
    }

    @ExceptionHandler//捕获异常
    public Result handle(NoResourceFoundException e){
        log.error("文件不存在:{} ",e.getResourcePath());
        return Result.fail("内部错误，请联系管理员");
    }
}
